package com.oracle.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.oracle.user.dao.UsersDao;
import com.oracle.role.entity.RoleEntity;
import com.oracle.user.entity.UsersEntity;
import com.oracle.user.feign.RoleFeignService;
import com.oracle.user.service.UsersService;
import com.oracle.user.vo.UserVo;
import com.oracle.util.Compents;
import com.oracle.util.PageUtils;
import com.oracle.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@Service("usersService")
public class UsersServiceImpl extends ServiceImpl<UsersDao, UsersEntity> implements UsersService {

    @Autowired
    private UsersDao usersDao;

    @Override
    public PageUtils<UsersEntity> queryPage(Map<String, Object> params,Integer pageNum,Integer pageSize) {
        //1、封装页码数据
        PageHelper.startPage(pageNum,pageSize);
        //2、模糊条件查询
        QueryWrapper<UsersEntity> queryWrapper = new QueryWrapper<UsersEntity>();
        queryWrapper.eq("status", Compents.USER_CODE1);  //用户状态字段
//        queryWrapper.eq("is_deleted",Compents.USER_CODE1);    //逻辑删除字段

        //2.1
        if(!ObjectUtils.isEmpty(params.get("name"))){
            queryWrapper.like("name",params.get("name"));
        }

        //3、name 为空则 全量 表查询 否则 根据条件查询
        Page<UsersEntity> page = (Page<UsersEntity>)usersDao.selectList(queryWrapper);

        return new PageUtils<UsersEntity>(page.getTotal(),page.getResult());
    }
}
